/**
 * @file cfcDatabase.cfc
 *   component used to handle database operations
 * @author Joshua Glovinsky
 **/
component 
{
	/**
	 * Function used for database queries
	 * @param colddoc:generic struct
	 **/
	 public function queryForResults ( Required String sql, Array params, String datasource, queryOnly, list) 
	 {
	 	if ( Not IsDefined ( "ARGUMENTS.datasource" ) ){
	 	 	datasource =  APPLICATION.datasource;
	 	}
	 	
	 	var q = new query();
	 	
	 	try {
	 		q.setDatasource ( datasource );
	 		q.setSQL ( sql );
	 		
	 		if ( ArrayLen ( params ) GT 0 ) {
	 		 	for ( i = 1; i LTE ArrayLen( params ); i++ ) {
	 		 	 	if ( StructKeyExists ( params[1], 'list' ) ) {
	 		 	 		q.addParam ( name = params[1].name, value = params[i].value, CFSQLTYPE = params[i].sqlType, list = "yes");
	 		 	 	} else {
	 		 	 		q.addParam ( name = params[1].name, value = params[i].value, CFSQLTYPE = params[i].sqlType);
	 		 	 	}
	 		 	}
	 		}
	 		if ( IsDefined ( "ARGUMENTS.queryOnly" ) AND ARGUMENTS.queryOnly EQ true ) {
	 			var r = q.execute();
	 			return r.getResult();
	 		} else {
	 			return q.execute();
	 		}
	 	} catch ( Any ex ) {
	 		WriteLog ( type = "ERROR", file = "cfcDatabase", text = " [#ex.type#] #ex.message#" );
	 	}
	 }
}